package com.guoliang.eduService.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guoliang.commonUtils.CommonResult;
import com.guoliang.eduService.entity.EduCourse;
import com.guoliang.eduService.entity.EduTeacher;
import com.guoliang.eduService.service.EduCourseService;
import com.guoliang.eduService.service.EduTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author ：Leo
 * @date ：Created in 2023/1/29 9:51
 * @description：
 */
@RestController
@RequestMapping("/eduService/teacherfront")
@Api(description = "讲师 前台")
public class TeacherFrontController {
    @Autowired
    private EduTeacherService teacherService;
    @Autowired
    private EduCourseService courseService;
    @ApiOperation("分页查询")
    @GetMapping("getTeacherFrontList/{page}/{limit}")
    public CommonResult getTeacherFrontList(@PathVariable("page")Long page,@PathVariable("limit")Long limit){
        Page<EduTeacher> pageTeacher=new Page<>(page,limit);
        Map<String, Object> teacherFrontList = teacherService.getTeacherFrontList(pageTeacher);
        return CommonResult.ok().date(teacherFrontList);
    }
    @ApiOperation("根据讲师id查询讲师所讲课程和讲师详情")
    @GetMapping("getTeacherInfo/{id}")
    public CommonResult getTeacherInfo(@PathVariable("id")String id){
        EduTeacher teacher = teacherService.getById(id);
        //查询所讲课程
        QueryWrapper<EduCourse> wrapper=new QueryWrapper<>();
        wrapper.eq("teacher_id",id);
        List<EduCourse> courseList = courseService.list(wrapper);
        return CommonResult.ok().data("teacher",teacher).data("course",courseList);
    }

}
